package com.woniuxy.microsportsserver.devicemag.controller;

import com.alibaba.fastjson.JSONObject;
import com.woniuxy.microsportsserver.bean.DeviceInfo;
import com.woniuxy.microsportsserver.devicemag.service.IDeviceService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RequestMapping("/device")
@RestController
public class DeviceController {
    @Resource
    private IDeviceService deviceService;
    /**
     * 全文检索实现接口
     * @param text
     * @param page 当前页码，从0开始
     * @param rows 每页显示的行数
     * @return
     */
    @GetMapping(value = "/search",produces = MediaType.APPLICATION_JSON_VALUE)
    public String search(String text,int page,int rows){
        Page<DeviceInfo> pages = deviceService.search(text, PageRequest.of(page,rows, Sort.by(Sort.Order.desc("id"))));
        System.out.println(pages);
        return JSONObject.toJSONString(pages);
    }
}
